
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="org.json.JSONObject"%>

<%
	Connection con = null;
	try {
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		con = DriverManager.getConnection(
				"jdbc:mysql://localhost:3306/cot", "root", "Beyer9499");

		ResultSet rs = null;
		List empdetails = new LinkedList();
		JSONObject responseObj = new JSONObject();

		String query = "SELECT count(yn) as prob, uid from itemdata join form on formid=fid where yn=0 group by form.uid";
		PreparedStatement pstm = con.prepareStatement(query);

		rs = pstm.executeQuery();
		JSONObject empObj = null;

		while (rs.next()) {
			int numProb = rs.getInt("prob");
			System.out.println(numProb);
			String uid =String.valueOf(rs.getInt("uid"));
			empObj = new JSONObject();
			empObj.put("numProb", numProb);
			empObj.put("uid", uid);
			empdetails.add(empObj);
		}
		responseObj.put("empdetails", empdetails);
		out.print(responseObj.toString());
		System.out.print(responseObj.toString());
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (con != null) {
			try {
				con.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
%>